﻿using Microsoft.SharePoint;
using System;
using System.Web;

namespace Eneta.Portal.Common.Definitions
{
    /// <summary>
    /// Enumerator class for SharePoint content type identificators. These 
    /// identificators are used everywhere where list item content types
    /// are used.
    /// </summary>
    public class ContentTypes
    {
        public const string Announcement = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900A935E49773E34506B2E774D53B4673F0";
        public const string Blog = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39007151C363D707BF45A07B1867B2A33CC7";
        public const string BlogEntry = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900E0362E34520E234DB684A6687E6BA2EC";
        public const string Company = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900F7E1298CADAF4c13A1BB6AB6BC6F009E";
        public const string Book = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900CFEEA8FC0B484bce98EB904C14F03170";
        public const string Magazine = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900E9E63518DD704681A709630A05C79C93";
        public const string Events = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900F9DF25D978A0E84BB6FCD770F9A7133B";
        
        /// <summary>
        /// Live ID profiles content type.
        /// </summary>
        public const string Profile = "0x01009AA75A93A2A44c2BB1D5C44B5141BEC0";

        public static string GetName(string contentTypeId)
        {
            var name = string.Empty;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (var site = new SPSite(EnetaApplication.PortalProfilePageUrl))
                using (var web = site.OpenWeb())
                {
                    var ctId = new SPContentTypeId(contentTypeId);
                    var ct = web.ContentTypes[ctId];
                    name = ct.Name;
                }
            });

            return name;
        }
    }
}
